const {ipcRenderer: ipc} = (window.require && window.require('electron')) || window.electron || {}
const ipcApiRoute = {
  test: 'controller.example.test',
  messageShow: 'controller.example.messageShow',
  messageShowConfirm: 'controller.example.messageShowConfirm',
  selectFolder: 'controller.example.selectFolder',
  openDirectory: 'controller.example.openDirectory',
  loadViewContent: 'controller.example.loadViewContent',
  removeViewContent: 'controller.example.removeViewContent',
  createWindow: 'controller.example.createWindow',
  sendNotification: 'controller.example.sendNotification',
  initPowerMonitor: 'controller.example.initPowerMonitor',
  getScreen: 'controller.example.getScreen',
  openSoftware: 'controller.example.openSoftware',
  autoLaunch: 'controller.example.autoLaunch',
  setTheme: 'controller.example.setTheme',
  getTheme: 'controller.example.getTheme',
  checkForUpdater: 'controller.example.checkForUpdater',
  downloadApp: 'controller.example.downloadApp',
  dbOperation: 'controller.example.dbOperation',
  sqlitedbOperation: 'controller.example.sqlitedbOperation',
  uploadFile: 'controller.example.uploadFile',
  checkHttpServer: 'controller.example.checkHttpServer',
  doHttpRequest: 'controller.example.doHttpRequest',
  doSocketRequest: 'controller.example.doSocketRequest',
  ipcInvokeMsg: 'controller.example.ipcInvokeMsg',
  ipcSendSyncMsg: 'controller.example.ipcSendSyncMsg',
  ipcSendMsg: 'controller.example.ipcSendMsg',
  getWCid: 'controller.example.getWCid',
  startJavaServer: 'controller.example.startJavaServer',
  closeJavaServer: 'controller.example.closeJavaServer',
  hello: 'controller.example.hello',
};

export default {

  /**
   * 使用客户端功能
   * import Ipc from '@/utils/ipcRenderer'
   * if (Ipc.ipc){
        console.log(Ipc);
        Ipc.invoke(Ipc.ipcApiRoute.test, {}).then(res => {
          console.log('res:', res)
        })
    }
   * */

  /**
   * 发送异步消息（invoke/handle 模型）
   * @param channel
   * @param param
   * @returns {Promise}
   */
  invoke: (channel, param) => {
    const message = ipc.invoke(channel, param);
    return message;
  },
  /**
   * 发送同步消息（send/on 模型）
   * @param channel
   * @param param
   * @returns {Any}
   */
  sendSync: (channel, param) => {
    const message = ipc.sendSync(channel, param);
    return message;
  },
  ipc,
  ipcApiRoute
}
